package testcasetool.transformation.presentation;

import java.util.HashMap;
import java.util.Map;

import testcasetool.transformation.uml.activity.Activity;
import testcasetool.transformation.uml.activity.ActivityFinalNode;
import testcasetool.transformation.uml.activity.ActivityNode;
import testcasetool.transformation.uml.activity.DecisionNode;

public class ActivityDiagramViewer {
	
	private Map<ActivityNode, ActivityNode> visitados = new HashMap<ActivityNode, ActivityNode>();

	public void prueba(String ppepe) {
		System.out.println("Entro: " + ppepe);
	}
	
	public void printAD(Activity ad) {
		System.out.println("Activity Diagram: " + ad.getName());
		System.out.println("Pre-Condition: " + ad.getPreCondition());
		System.out.println("Post-Condition: " + ad.getPostCondition());
		
		this.printNodes(ad.getInitialNode());
	}

	private void printNodes(ActivityNode node) {
		if (visitados.containsKey(node)) {
			System.out.println("Jump: @"+ node);
			return;
		}
		visitados.put(node, node);
		if (node instanceof DecisionNode) {
			System.out.println("["+ ((DecisionNode)node).getOutgoings().get(0).getGuard() +"]");
			printNodes(node.getOutgoings().get(0).getTarget());
			System.out.println("["+ ((DecisionNode)node).getOutgoings().get(1).getGuard() +"]");
			printNodes(node.getOutgoings().get(1).getTarget());
		} else if (node instanceof ActivityFinalNode){
			System.out.println(node);
		} else {
			System.out.println(node);
			printNodes(node.getOutgoings().get(0).getTarget());
		}
		
	}
}
